package com.mvvmhabit.org.http

import android.os.Handler
import android.os.Looper
import io.reactivex.Scheduler
import io.reactivex.schedulers.Schedulers
import java.util.concurrent.Executor

class AndroidScheduler : Executor {

    companion object {
        var instance: AndroidScheduler? = null

        @Synchronized
        fun mainThread(): Scheduler {
            if (instance == null) {
                instance = AndroidScheduler()
            }
            return instance!!.mMainScheduler
        }
    }

    private var mMainScheduler: Scheduler = Schedulers.from(this)

    private var mHandler: Handler = Handler() // Looper.myLooper()

    override fun execute(p0: Runnable) {
        mHandler.post(p0)
    }

}